#include "Tree.h"

void DestoryTreeNode(TreeNode* root)
{
	if (root == NULL)
	{
		return;
	}
	if (root->left)
	{
		DestoryTreeNode(root->left);
	}
	if (root->right)
	{
		DestoryTreeNode(root->right);
	}
	free(root);
	root = NULL;
}

TreeNode* CreateTreeNode(TreeNode** root)
{
	char ch;
	scanf("%c", &ch);
	if (ch == '#')
	{
		*root = NULL;
	}
	else
	{
		*root = (TreeNode*)malloc(sizeof(TreeNode));
		(*root)->data = ch;
		(*root)->left = CreateTreeNode(&((*root)->left));
		(*root)->right = CreateTreeNode(&((*root)->right));
	}
	return *root;
}

bool EmptyTreeNode(TreeNode* root)
{
	if (root)
	{
		return false;
	}
	return true;
}

int DepthTreeNode(TreeNode* root)
{
	if (root == NULL)
	{
		return 0;
	}
	int left = DepthTreeNode(root->left);
	int right = DepthTreeNode(root->right);
	return (left > right ? left : right) + 1;
}

void PreOrderTreeNode(TreeNode* root)
{
	if (root == NULL)
	{
		return;
	}
	printf("%c ", root->data);
	PreOrderTreeNode(root->left);
	PreOrderTreeNode(root->right);
}

void InOrderTreeNode(TreeNode* root)
{
	if (root == NULL)
	{
		return;
	}
	PreOrderTreeNode(root->left);
	printf("%c ", root->data);
	PreOrderTreeNode(root->right);
}

void PostOrderTreeNode(TreeNode* root)
{
	if (root == NULL)
	{
		return;
	}
	PreOrderTreeNode(root->left);
	PreOrderTreeNode(root->right);
	printf("%c ", root->data);
}

